package com.lycx.businessmanager.controller.customerManager;

import java.util.List;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;


import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.lycx.businessmanager.controller.BaseController;
import com.lycx.businessmanager.model.Customer;
import com.lycx.businessmanager.service.ICustomerService;

/**
 * 客户controller
 * 
 * @author lambert
 * 
 */

@Controller
@RequestMapping("/customer")
public class CustomerController extends BaseController{
	@SuppressWarnings("unused")
	private static Logger log = Logger.getLogger(CustomerController.class);
	private ICustomerService customerService;

	public void setcustomerService(ICustomerService customerService) {
		this.customerService = customerService;
	}

	@RequestMapping(value = "/list")
	public ModelAndView list(HttpServletRequest request, HttpServletResponse response) {
		ModelAndView mv = new ModelAndView("/customer/list");
		return mv;
	}
	
	@RequestMapping(value = "/getListForPage")
	@ResponseBody
	public List<Customer> getListForPage(Customer customer,int startNum,int limit){
		List<Customer> customerList = null;
		try{
		    customerList = customerService.selectForPage(customer,startNum,limit);
		}catch(Exception e){
			e.printStackTrace();
		}
        return customerList;
	}
	
	@RequestMapping(value = "/getTotalCount",method = RequestMethod.POST)
	@ResponseBody
	public int getTotalCount(Customer customer){
		return customerService.selectTotalCount(customer);
	}
	
	@RequestMapping(value = "/add",method = RequestMethod.POST)
	@ResponseBody
	public String add(Customer customer){
		String result = null;
		if(customer!=null){
	        result = customerService.add(customer);
		}
        return result;
	}
	
	@RequestMapping(value = "/del",method = RequestMethod.POST)
	@ResponseBody
	public String del(HttpServletRequest request, HttpServletResponse response,int ids[]){
		String result = null;
		result = customerService.del(ids);
		return result;
	}
	
	@RequestMapping(value = "/mod",method = RequestMethod.POST)
	@ResponseBody
	public String mod(HttpServletRequest request, HttpServletResponse response,Customer customer){
		String result = null;
		if(customer!=null){
			result = customerService.mod(customer);
		}
		return result;
	}

}
